function Scene(context, player) {
  this.player = player;
  this.waves = [];

  this.horizonY = -300;
  this.oceanGradient =
      context.createLinearGradient(0, this.horizonY, 0, 500);
  this.oceanGradient.addColorStop(0, 'rgb(0, 0, 255)');
  this.oceanGradient.addColorStop(1, 'rgb(0, 0, 128)');  
}

Scene.prototype.update = function(dt) {
  for (var i = 0; i < this.waves.length; i++) {
    this.waves[i].life--;
    this.waves[i].x += this.waves[i].vX * dt;     
    this.waves[i].y += this.waves[i].vY * dt; 
    if (this.waves[i].y < -50) {
      this.waves[i].y = -50;
    }
    if (this.waves[i].life < 0) {
      this.waves.splice(i, 1);
      i--;
    }
  }
}

Scene.prototype.renderBackground = function(context) {
  var halfWidth = context.canvas.width/2;
  var halfHeight = context.canvas.height/2;

  if (player.y + halfHeight > this.horizonY) {
    context.fillStyle = this.oceanGradient;
    context.fillRect(player.x - halfWidth, 
      this.horizonY, canvas.width, -this.horizonY + 15);
  }
}

Scene.prototype.renderForeground = function(context) {
  var halfWidth = context.canvas.width/2;
  var halfHeight = context.canvas.height/2;

  //if (player.y + halfHeight > 0) {
    context.fillStyle = this.oceanGradient;
    context.fillRect(player.x - halfWidth, 
      10, canvas.width, player.y + halfHeight);

    for (var i = 0; i < this.waves.length; i++) {
      var radius = this.waves[i].life * 0.1 + 5;
      if (radius > 0) {
        context.beginPath();
        context.arc(this.waves[i].x, this.waves[i].y, 
          radius, Math.PI, 2*Math.PI, false);
        context.fillStyle = 'rgba(100, 150, 255, 1.0)';
        context.fill();
      }
    }
  //}
}

Scene

Scene.prototype.addWaves = function(x, life) {
  if (life > 1000) {
    life = 1000;
  }
  var wave = {};
  wave.x = x +  Math.random() * 25 - 12;
  wave.y = 10 + Math.random() * 10 - 5;
  wave.vX = 20 * Math.random() - 10;  
  wave.vY = 50 * Math.random() - 25;
  wave.life = life * (Math.random() + 0.5);
  this.waves.push(wave);
}
